﻿package helpers;
/**
 * A threadsafe counter class
 * @author Mark Bracke
 */
public class SafeCounter
{
	private int count;
	
	public int getCount() {
		return count;
	}
	
	private void setCount(int count) {
		this.count = count;
	}

	/**
	 * Constructs a new SafeCounter with an initialValue
	 * @param initialValue the initial value
	 */
    public SafeCounter(int initialValue)
    {
        setCount(initialValue);
    }

    /**
     * Adds a certain amount to this safe counter
     * @param amount the amount to add to this counter
     */
    public synchronized void add(int amount)
    {
        this.count += amount;
    }

    /**
     * Subtracts a certain amount from this safe counter
     * @param amount the amount to subtract from this counter
     */
    public synchronized void subtract(int amount)
    {
        this.count -= amount;
    }
}
